#pragma once

#include "comm/my_defs.h"
#include "comm/my_spin_lock.h"
#include "comm/my_rbtree.h"
#include "comm/my_queue.h"
#include "comm/my_buf.h"
#include "cache/util/my_cache_key.h"

typedef struct my_slru_cache_s my_slru_cache_t;

struct my_slru_cache_s {
    my_spin_lock_t                  lock;
    int64_t                         max_item;
    int64_t                         max_bytes;

    int                             nlist;
    my_queue_t                      *lists;
    int64_t                         *lists_bytes;
    int64_t                         *lists_n;

    my_rbtree_t                     tree;
    my_rbtree_node_t                sentinel;
};

void
my_slru_cache_open(my_slru_cache_t *slru_cache, int nlists,
    int64_t max_item, int64_t max_bytes);

void
my_slru_cache_close(my_slru_cache_t *slru_cache);

my_bool_t
my_slru_cache_get(my_slru_cache_t *slru_cache, my_cache_key_t *key,
    my_buf_chain_t *data);

void
my_slru_cache_put(my_slru_cache_t *slru_cache, my_cache_key_t *key,
    my_buf_chain_t *data);

void
my_slru_cache_remove(my_slru_cache_t *slru_cache, my_cache_key_t *key);